package com.financial.service.heemoney.service.impl;

import com.financial.service.heemoney.convertor.HeemoneyProviderQueryConvert;
import com.financial.service.heemoney.dto.HeemoneyConfigDTO;
import com.financial.service.heemoney.dto.businsess.HeemoneyProviderQueryBusinessDTO;
import com.financial.service.heemoney.dto.commmon.HeemoneyProviderQueryCommonDTO;
import com.financial.service.heemoney.dto.inparameter.HeemoneyProviderQueryInParamDTO;
import com.financial.service.heemoney.dto.param.HeemoneyProviderQueryParamDTO;
import com.financial.service.heemoney.service.FinancialProQueryHeemoneylogService;
import com.financial.service.heemoney.service.FinancialReportHeemoneyService;
import com.financial.service.heemoney.service.FinancialWxconfigHeemoneylogService;
import com.financial.service.heemoney.utils.JsonUtils;
import com.financial.service.heemoney.utils.OkHttpUtils;
import com.financial.service.heemoney.utils.ResultUtils;
import com.financial.service.heemoney.utils.apiresult.ApiResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @api {post}
 * @apiExample author zhaopengjun
 * tar 汇收银进件查询服务
 * date   2019/12/25 18:01
 * @apiGroup
 * @apiVersion 1.0.0
 * @apiHeader
 * @apiParam
 * @apiSuccess
 */
@Service
public class FinancialProQueryHeemoneylogServiceImpl implements FinancialProQueryHeemoneylogService {
    public static final Logger log = LoggerFactory.getLogger(FinancialPayHeemoneyServiceImpl.class);
    @Autowired
    private OkHttpUtils okHttpUtils;
    @Autowired
    private FinancialReportHeemoneyService financialReportHeemoneyService;
    @Autowired
    private FinancialWxconfigHeemoneylogService financialWxconfigHeemoneylogService;

    @Override
    public ApiResult providerQuery(HeemoneyProviderQueryInParamDTO heemoneyProviderQueryInParamDTO) {
        log.info("调用金融中心汇收银服务层商户统一进件查询接口前参数打印：{}", JsonUtils.beanToJson(heemoneyProviderQueryInParamDTO));
        //数据转实体校验参数非空
        HeemoneyProviderQueryCommonDTO heemoneyProviderQueryCommonDTO = HeemoneyProviderQueryConvert.MAPPER.configConvertCommonDTO(new HeemoneyConfigDTO(), heemoneyProviderQueryInParamDTO);
        HeemoneyProviderQueryBusinessDTO heemoneyProviderQueryBusinessDTO = HeemoneyProviderQueryConvert.MAPPER.configConvertBusinessDTO(new HeemoneyConfigDTO(), heemoneyProviderQueryInParamDTO);
        HeemoneyProviderQueryParamDTO heemoneyProviderQueryParamDTO = new HeemoneyProviderQueryParamDTO(heemoneyProviderQueryCommonDTO, heemoneyProviderQueryBusinessDTO);
        log.info("http请求汇收银服务层商户进件查询接口入参：{}", heemoneyProviderQueryParamDTO.getJsonParam());
        try {
            String resultStr = okHttpUtils.postJsonParams(new HeemoneyConfigDTO().getHeemoneyProviderQuery().getRequest_url(), heemoneyProviderQueryParamDTO.getJsonParam());
            log.info("http请求汇收银服务层商户进件查询接口回执:{}", resultStr);
            //返回调用信息
            return ResultUtils.resultStr(resultStr);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("http请求汇收银服务层商户进件查询接口失败：{}", heemoneyProviderQueryInParamDTO.getMch_uid());
        }
        return ApiResult.failure();
    }

}
